<?php
//订单模型
namespace Admin\Model;
use Think\Model;

/**
 * 用户模型
 */
class orderModel extends Model{
    
    protected $tableName = 'order';

    /**
     * 自动完成
     * @var array
     */
    protected $_auto = array(
    );
    

    /*
     * 自动验证
     */
    protected $_validate = array(
     );
    
    /*
     * 获取列表
     */
    public function getOrderList($where,$page){
        $res = $this->where($where)->order('order_id DESC')->page($page,10)->select();
        return $res;
    }
    
    /*
     * 获取列表
     */
    public function getOrderLists($where){
        $res = $this->where($where)->order('order_id DESC')->limit(500)->select();
        return $res;
    }
	
    /*
     * 统计数量
     */
    public function getOrderCount($where){
        $res = $this->where($where)->count();
        return $res;
    }
    
    /*
     * 添加
     */
    public function addOrder($data){
        $res = $this->add($data);
        return $res;
    }
    
    /*
     * 获取信息
     */
    public function getOrder($where){
        $res = $this->where($where)->find();
        return $res;
    }
	
    /*
     * 编辑信息
     */
    public function editOrder($where,$data){
        return $this->where($where)->save($data);
    }
    

    /*
     * 计算昨天的业绩
     * 订单类型0注册，1重消 2升级
     */
    public function sumYeji($type){
      
        $where = array(
            'order_type' => $type,
            'checked' => array('in',array('1','2','5')),
            
        );

        $start = date("Y-m-d",strtotime("-1 day")).' 00:00:00';
        $end = date("Y-m-d").' 00:00:00';
        $time = "create_time>='".$start."'";
		$time .= " AND create_time<='".$end."'"; 
        $res = $this->where($time)->where($where)->sum('order_cashmoney');
        return $res;
        
    }
    
    
    
}
